#pragma once                                                                                                           
#include <iostream>
#include <cstring>    
#include <cstdio>
#include <cstdlib>
#include <sys/socket.h>    
#include <sys/types.h>    
#include <netinet/in.h>    

#define NUMBERS 16

using namespace std;  

namespace TcpSocket
{
    class server
    {    
    public:    
        static int Socket()
        {    
            int sock = socket(AF_INET, SOCK_STREAM, 0);
            if (sock < 0) 
            {
                perror("socket error");
                exit(-1);
            }    
            return sock;
        }    

        static void Bind(int sockfd, uint16_t port)
        {    
            struct sockaddr_in addr;    
            memset(&addr, 0, sizeof(addr));
            addr.sin_family = AF_INET;    
            addr.sin_port = htons(port);
            addr.sin_addr.s_addr = 0;
            int n = bind(sockfd, (struct sockaddr*)&addr, sizeof(addr));
            if(n < 0) 
            {
                perror("bind error");
                exit(-1);    
            }     
        }    
 
        static void Listen(int sockfd)
        {
            if(listen(sockfd, NUMBERS) < 0) 
            {
                perror("listen error");
                exit(-1);
            }
        }
    };
}